/*
 * Copyright (c)  2017
 * All rights reserved.
 * OrderEntity.java 2017-09-17 下午2:59
 */

package com.ueboot.weishop.entity.order;

import com.ueboot.weishop.entity.IDEntity;
import com.ueboot.weishop.entity.customer.CustomerCouponEntity;
import com.ueboot.weishop.entity.customer.CustomerInfoEntity;
import com.ueboot.weishop.entity.customer.CustomerInvoiceEntity;
import com.ueboot.weishop.entity.customer.CustomerReceiverEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Date;

/**
 * 描述:订单信息
 * 订单下有订单项、订单发票、订单收货和快递信息表
 *
 * @author yangkui create on 2017-09-17 下午2:59.
 * @since 1.0
 */
@Data
@NoArgsConstructor
@Entity(name = "WS_ORDER")
public class OrderEntity extends IDEntity {

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "WS_ORDER")
	@GenericGenerator(name = "WS_ORDER", strategy = "enhanced-table", parameters = {
			@org.hibernate.annotations.Parameter(name = "table_name", value = "WS_TABLE_SEQUENCE"),
			@org.hibernate.annotations.Parameter(name = "segment_value", value = "WS_ORDER"),
			@org.hibernate.annotations.Parameter(name = "optimizer", value = "pooled")})
	@Column(name = "ID", columnDefinition = "INT(20) COMMENT 'id主键'", length = 20)
	private Long id;

	/**
	 * 订单编号
	 */
	@Column(name = "ORDER_NO", columnDefinition = "VARCHAR(40) COMMENT '订单编号'", length = 40)
	private String orderNo;

	/**
	 * 所属分类名称
	 */
	@Column(name = "CATEGORY_NAME", columnDefinition = "VARCHAR(40) COMMENT '所属分类名称'", length = 40)
	private String categoryName;

	/**
	 * 所属分类代码
	 */
	@Column(name = "CATEGORY_CODE", columnDefinition = "VARCHAR(40) COMMENT '所属分类代码'", length = 40)
	private String categoryCode;

	/**
	 * 商品名称（冗余字段。如果多个商品，则用，分割）
	 */
	@Column(name = "GOODS_NAME", columnDefinition = "VARCHAR(200) COMMENT '商品名称（冗余字段。如果多个商品，则用，分割）'", length = 200)
	private String goodsName;

	/**
	 * 商品主图地址(冗余）
	 */
	@Column(name = "MAIN_IMG_URL", columnDefinition = "VARCHAR(200) COMMENT '商品主图地址'", length = 200)
	private String mainImgUrl;

	/**
	 * 订单中的商品数量
	 */
	@Column(name = "GOODS_COUNT", columnDefinition = "INT(11) COMMENT '订单中的商品数量'", length = 11)
	private Integer goodsCount;

	/**
	 * 客户微信openId
	 */
	@Column(name = "CUSTOMER_OPEN_ID", columnDefinition = "VARCHAR(40) COMMENT '客户微信openId'", length = 40)
	private String customerOpenId;
	/**
	 * 用于当前活动针对客户限购的唯一身份标识，可以是openId,vin,mobile。具体由活动本身决定
	 */
	@Column(name = "KEY_FOR_LIMIT", columnDefinition = "VARCHAR(40) COMMENT '用于当前活动限购的唯一身份标识，可以是openId,vin,mobile。具体由活动本身决定'", length = 40)
	private String keyForLimit;


	/**
	 * 用于统计当前产品的库存计算方式。根据活动类型不同，记录的key值也不同
	 */
	@Column(name = "COUNT_KEY", columnDefinition = "VARCHAR(80) COMMENT '用于统计当前产品的库存计算方式。根据活动类型不同，记录的key值也不同'", length = 40)
	private String countKey;


	/**
	 * 下订单时间
	 */
	@Column(name = "ORDER_TIME", columnDefinition = "DATE COMMENT '下订单时间'")
	private Date orderTime;

	/**
	 * 支付时间,接收到支付回调时间
	 */
	@Column(name = "PAY_TIME", columnDefinition = "DATE COMMENT '支付时间,接收到支付回调时间'")
	private Date payTime;

	/**
	 * 单一活动代码时的活动代码
	 */
	@Column(name = "ACTIVITY_SN", columnDefinition = "VARCHAR(40) COMMENT '单一活动代码时的活动代码'")
	private String activitySN;

	/**
	 * 单一活动代码时的活动分类
	 */
	@Column(name = "ACTIVITY_TYPE", columnDefinition = "VARCHAR(40) COMMENT '单一活动代码时的活动分类'")
	private String activityType;

	/**
	 * 单一活动代码时的活动名称
	 */
	@Column(name = "ACTIVITY_NAME", columnDefinition = "VARCHAR(40) COMMENT '单一活动代码时的活动名称'")
	private String activityName;

	/**
	 * 参加的活动ID集合，使用/分割。
	 */
	@Column(name = "ACTIVITY_FULL_PATH_IDS", columnDefinition = "VARCHAR(40) COMMENT '所属活动ID集合，使用/分割。'", length = 200)
	private String activityFullPathIds;

	/**
	 * 参加的活动名称集合，使用/分割.
	 */
	@Column(name = "ACTIVITY_FULL_PATH_NAME", columnDefinition = "VARCHAR(40) COMMENT '所属活动名称集合，使用/分割.'", length = 200)
	private String activityFullPathName;

	/**
	 * 参加到的活动内容，直接将该订单享受到的活动内容文字描述。如：
	 * 限时折扣8折。满100减10.
	 */
	@Column(name = "ACTIVITY_CONTENT", columnDefinition = "VARCHAR(40) COMMENT '参加到的活动内容，直接将该订单享受到的活动内容文字描述'", length = 2000)
	private String activityContent;

	/**
	 * 订单原始价格
	 * 分为单位
	 */
	@Column(name = "ORIGINAL_PRICE", columnDefinition = "int(11) COMMENT '订单原始价格，分为单位'", length = 11)
	private Integer originalPrice;


	/**
	 * 订单最终支付金额(单位分）
	 */
	@Column(name = "PAY_AMOUNT", columnDefinition = "INT(11) COMMENT '订单最终支付金额(单位分）'", length = 11)
	private Integer payAmount;

	/**
	 * 所属客户信息
	 */
	@ManyToOne
	@JoinColumn(name = "CUSTOMER_ID", columnDefinition = "INT(20) COMMENT '所属客户信息'")
	private CustomerInfoEntity customer;

	/**
	 * 所使用的优惠券
	 */
	@ManyToOne
	@JoinColumn(name = "CUSTOMER_COUPON_ID", columnDefinition = "INT(20) COMMENT '所使用的优惠券'")
	private CustomerCouponEntity customerCoupon;

	/**
	 * 订单状态：未支付，支付中，已支付,已过期
	 */
	@Column(name = "ORDER_STATUS", columnDefinition = "VARCHAR(10) COMMENT '订单状态：未支付，支付中，已支付'")
	private String orderStatus = OrderEnum.ORDER_STATUS_0;

	/**
	 * 扩展状态，由其他业务逻辑处理，比如是否已经下发其他系统
	 */
	@Column(name = "EXT_STATUS", columnDefinition = "INT(11) COMMENT ' 扩展状态，由其他业务逻辑处理，比如是否已经下发其他系统'", length = 11)
	private Integer extStatus;

	/**
	 * 支付有效期
	 */
	@Column(name = "PAY_VALID_TIME", columnDefinition = "DATE COMMENT '支付有效期'")
	private Date payValidTime;

	/**
	 * 退款有效期
	 */
	@Column(name = "APPLY_REFUND_VALID_TIME", columnDefinition = "DATE COMMENT '退款有效期'")
	private Date applyRefundValidTime;

	/**
	 * 申请退款时间
	 */
	@Column(name = "APPLY_REFUND_TIME", columnDefinition = "DATE COMMENT '申请退款时间'")
	private Date applyRefundTime;

	/**
	 * 实际退款时间
	 */
	@Column(name = "REFUND_TIME", columnDefinition = "DATE COMMENT '实际退款时间'")
	private Date refundTime;

	/**
	 * 退款申请状态：未申请，待审核，退款成功，退款失败
	 */
	@Column(name = "REFUND_STATUS", columnDefinition = "VARCHAR(50) COMMENT '退款申请状态：未申请，待审核，退款成功，退款失败'", length = 50)
	private String refundStatus = OrderEnum.REFUND_STATUS_0;

	/**
	 * 申请退款理由
	 */
	@Column(name = "REFUND_REASON", columnDefinition = "VARCHAR(200) COMMENT '申请退款理由'", length = 200)
	private String refundReason;

	/**
	 * 审核结果：搭配退款失败
	 */
	@Column(name = "REFUND_AUDIT_RESULT", columnDefinition = "VARCHAR(200) COMMENT '不通过原因：退款失败搭配'", length = 200)
	private String refundAuditResult;

	/**
	 * 微信支付订单号：退款使用,支付成功后需填写此值
	 */
	@Column(name = "TRANSACTION_NO", columnDefinition = "VARCHAR(50) COMMENT '微信支付订单号：退款使用,支付成功后需填写此值'", length = 50)
	private String transactionNo;

	/**
	 * 是否需要发票以及合同
	 */
	@Column(name = "NEED_INVOICE", columnDefinition = "INT(1) COMMENT '是否需要发票以及合同'", length = 1)
	@Type(type = "org.hibernate.type.NumericBooleanType")
	private Boolean needInvoice = Boolean.FALSE;

}
